#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e5+5;
int n;
struct node{int a,b;}p[Maxn];
inline bool cmp(node a,node b){
	return a.b<b.b;
}
multiset<int>s;
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)p[i]={read(),read()};
	sort(p+1,p+1+n,cmp);
	s.insert(p[n].a+p[n].b);
	s.insert(p[n-1].a+p[n-1].b);
	int ans=1e18;
	for(int i=n-2;i;i--){
		int fir=*s.begin();s.erase(s.find(fir));
		ans=min(ans,p[i].a+fir+(*s.begin()));
		s.insert(fir);
		s.insert(p[i].a+p[i].b);
	}printf("%lld\n",ans);
	return 0;
}
/*
6
1 1
4 5
1 4
1 9
1 9
8 10
*/
